package aom.ju.ss.view.user.shop.management.goods.addGoods

import android.os.Bundle
import android.os.Message
import aom.ju.ss.R
import aom.ju.ss.databinding.AddGoodsHeadBinding
import aom.ju.ss.mode.LpKey
import aom.ju.ss.utils.start
import aom.ju.ss.utils.startResult
import aom.ju.ss.view.base.BaseFragment
import aom.ju.ss.view.base.UpMode
import aom.ju.ss.view.base.UploadFilesFragment
import com.google.gson.Gson

class AddGoodsHead : BaseFragment() {

    companion object {
        fun getMy(
            isCut: Boolean,
            is_goods_type: String
        ): AddGoodsHead {
            val b = AddGoodsHead()
            val bundle = Bundle()
            bundle.putBoolean("isCut", isCut)
            bundle.putString("Is_goods_type", is_goods_type)
            b.arguments = bundle
            return b
        }

    }

    lateinit var binding: AddGoodsHeadBinding
    var goodsBanner: UploadFilesFragment? = null
    var goodsDetails: UploadFilesFragment? = null
    override fun init() {
        binding = viewBinding as AddGoodsHeadBinding
        goodsBanner?.binding?.rootView?.tag = "banner"
        goodsDetails?.binding?.rootView?.tag = "details"
        childFragmentManager.findFragmentById(R.id.goods_banner)?.let {
            goodsBanner = it as UploadFilesFragment
        }
        childFragmentManager.findFragmentById(R.id.goods_details)?.let {
            goodsDetails = it as UploadFilesFragment
        }
        binding.className.setOnClickListener {
            activity.startResult(IndustryClassActivityAddGoods::class.java,1993)
        }
    }

    override fun callBack(event: Message?) {
        super.callBack(event)
        if (LpKey.UP_IMG_OK == event?.arg1) {
            val mode = Gson().fromJson(event.obj.toString(), UpMode::class.java)
            if (mode.tag == "banner") {
                NewCreateGoodsActivity.photo_album.clear()
                NewCreateGoodsActivity.photo_album.addAll(mode.list)
            } else if (mode.tag == "details") {
                NewCreateGoodsActivity.content_images.clear()
                NewCreateGoodsActivity.content_images.addAll(mode.list)
            }
        }
    }

    override fun getLay(): Int {
        return R.layout.add_goods_head
    }


}